home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 11507 < prev    next >
Encoding:
Text File  |  1996-08-05  |  2.9 KB  |  70 lines

  1. Newsgroups: comp.lang.c
  2. Path: howland.reston.ans.net!torn!sq!msb
  3. From: msb@sq.com (Mark Brader)
  4. Subject: Re: Newbie Questions
  5. Message-ID: <1996Mar24.204332.14841@sq.com>
  6. Organization: SoftQuad Inc., Toronto, Canada
  7. References: <4irpc1$b8u@GRAPEVINE.LCS.MIT.EDU> <4isgta$7cr@newsbf02.news.aol.com> <827628456snz@genesis.demon.co.uk> <3154C7FA.B38@iadfw.net>
  8. Date: Sun, 24 Mar 1996 20:43:32 GMT
  9.  
  10. MVaccaro1:
  11. > > >   printf( "Sizeof s1 %d\n Sizeof s2 %d\n", sizeof s1, sizeof s2 );
  12.  
  13. Lawrence Kirby:
  14. > > Anything can happen since sizeof doesn't return an int value, it returns
  15. > > a value with some implementation specific unsigned type (size_t).
  16.  
  17. Larry Weiss:
  18. > Since printf() is a member of the standard library (with unambiguous
  19. > semantics) couldn't the implementation be required to issue a diagnostic
  20. > if a mismatch were attempted?
  21.  
  22. The standard could have required this, but it also could have required
  23. diagnostics for array bounds violations, arithmetic exceptions, and all
  24. sorts of other things that now cause undefined behavior.  Instead, the
  25. standard-writers chose to avoid requiring most such diagnostics, leaving
  26. them instead as quality-of-implementation matters.
  27.  
  28. Larry may be thinking that the necessary checking could easily be done at
  29. compile time.  This is true only if the format argument is a string literal
  30. (or other constant string); in general, the check is a run-time operation.
  31. Internally, the compiler would probably turn
  32.  
  33.        printf (make_a_format(), sizeof s1, sizeof s2);
  34.  
  35. into something like:
  36.  
  37.     {
  38.     char *_fmt = make_a_format();
  39.     _check_printf_format (_fmt, _UNSIGNED_INT, _UNSIGNED_INT, _END);
  40.     printf (_fmt, sizeof s1, sizeof s2);
  41.     }
  42.  
  43. > If so, would the Standard need to say so explicitly?
  44.  
  45. In effect.  It would do so by putting a statement such as "The arguments
  46. following the format shall correspond to the conversion specifications
  47. in the format, as detailed below." into a Constraints section in 7.9.6.1.
  48. Making it a Constraint is what forces the diagnostic.
  49.  
  50. Nothing in the standard ever forces a diagnostic to say something useful.
  51. The "ed" mode of error reporting, where any error is reported as "?", is
  52. permitted.  Better error reporting is a quality-of-implementation issue.
  53.  
  54. Conversely, nothing in the standard ever *forbids* a diagnostic, no
  55. matter whether undefined behavior exists or not.  A compiler is allowed
  56. to diagnose *every* program with "?".  But it wouldn't find many buyers.
  57. In particular, a compiler is allowed to diagnose the situations that
  58. Larry is asking about, and I hear there are some that do.
  59.  
  60. > The information is clearly available to the implementation to support an
  61. > unambiguous diagnostic.
  62.  
  63. Yes, but as noted above, it may require some work to do it, and the
  64. standard is reluctant to force implementations to do that sort of work.
  65. -- 
  66. Mark Brader, msb@sq.com             "Ask not for whom the compiler waits;
  67. SoftQuad Inc., Toronto               it waits for thee."   -- Henry Spencer
  68.  
  69. My text in this article is in the public domain.
  70.